/* Copyright Thanh-Trung Pham, 2015 */
package jp.ac.uaizu.generation;

import jp.ac.jaist.input.RMPIIAWrapper;
import jp.ac.jaist.input.RMPIInputModeler;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Thanh-Trung Pham
 */
public class OutputModel {
    private static final String COMMA = ",";
    private final Set<Set<String>> m_oAIOS;
    private Set<Set<String>> m_oAFS;

    private RMPIIAWrapper m_oEquivalentIAWrapper;

    /**
     * The constructor.
     *
     * @param equivalentIA     the equivalent internal activity.
     * @param rmpiInputModeler the RMPI input modeler.
     */
    public OutputModel(RMPIIAWrapper equivalentIA, RMPIInputModeler rmpiInputModeler) {
        m_oEquivalentIAWrapper = equivalentIA;
        m_oAFS = rmpiInputModeler.getAFS();
        m_oAIOS = rmpiInputModeler.getAIOS();
    }

    /**
     * Get the reliability.
     *
     * @return the reliability.
     */
    public double getReliability() {
        return m_oEquivalentIAWrapper.getProbability(RMPIInputModeler.RMPI_F0_AS_SET, RMPIInputModeler.RMPI_F0_AS_SET);
    }

    /**
     * Get the failure probability of the given failure types.
     *
     * @param involvedFailures the given failure types.
     * @return the failure probability of the given failure types.
     */
    public double getFailureProbability(String involvedFailures) {
        Set<String> oInvolvedFailuresAsSet = new HashSet<String>();

        oInvolvedFailuresAsSet.addAll(Arrays.asList(StringUtils.split(involvedFailures, COMMA)));

        return m_oEquivalentIAWrapper.getProbability(RMPIInputModeler.RMPI_F0_AS_SET, oInvolvedFailuresAsSet);
    }

    /**
     * Get the failure probability of the given failure types.
     *
     * @param involvedFailures the given failure types.
     * @return the failure probability of the given failure types.
     */
    public double getFailureProbability(Set<String> involvedFailures) {
        return m_oEquivalentIAWrapper.getProbability(RMPIInputModeler.RMPI_F0_AS_SET, involvedFailures);
    }


    /**
     * Get the AIOS set.
     *
     * @return the AIOS set.
     */
    public Set<Set<String>> getAIOS() {
        return m_oAIOS;
    }

    /**
     * Get the AFS set.
     *
     * @return the AFS set.
     */
    public Set<Set<String>> getAFS() {
        return m_oAFS;
    }
}
